<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page language="java" import="java.lang.*" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "com.seniorproject.aims.*" %>
<%@ page import = "java.util.List" %>
<%@page import="java.util.ArrayList"%>
<%@ page import = "java.util.Properties" %>
<%@ page import = "javax.servlet.ServletContext" %>
<%@ page import = "java.io.File" %>
<%@ page import = "java.io.InputStream" %>
<%@ page import = "java.sql.PreparedStatement" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Add Course to Schedule</title>
<link rel="stylesheet" type="text/css" href="css/stylev2.css" />

<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>

<style type="text/css">
	a {
      text-decoration:none;
   }
</style>

<script type="text/javascript">	

	
		function search_name(courseid) {
			if($('#namelist').find('option').length > 0) {
				
				$('#namelist').find('option').remove();
			}
			var CurriculumId = (document.getElementById('CurriculumId')).value;		
			
			if(courseid.length>2) {
				
				/* AJAX */
				var xmlhttp;
				
				if(window.XMLHttpRequest) {
					// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
				else {
					// code for IE6, IE5
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				
				xmlhttp.onreadystatechange = function() {
					if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						
						
						var jsonObj = JSON.parse(xmlhttp.responseText);
						
						if(jsonObj.length == 0) {
							// no data
						}
						else{
							// show data
							for(i in jsonObj) {
								var text = jsonObj[i].courseId+" , "+jsonObj[i].courseNameEN+" , "+jsonObj[i].credit+" ( "+jsonObj[i].lecture+" "+jsonObj[i].lab+" "+jsonObj[i].selfLearn+" ) , "+jsonObj[i].details;
								var option = '<option value="'+text+'" >';
								$('#namelist').append(option);								
							}
							var result = document.getElementById("search_box").value;	
							
						}
					}
					
				}
				
				xmlhttp.open("POST", "curriculum_search_course_name_schedule.jsp?courseid="+courseid+"&CurriculumId="+CurriculumId, true);
				xmlhttp.send();
				
			}	
		}	
		
</script>


</head>
<body>
<%
//Get session
String strUser = String.valueOf(session.getAttribute("sUser"));
HttpSession htp_session = request.getSession();
		
if (htp_session == null || htp_session.getAttribute("sUser") == null) {
    // Forward the control to login.jsp if authentication fails or session expires
    request.getRequestDispatcher("/login.jsp").forward(request,
        response);
}

if("admin".equals(htp_session.getAttribute("sUser"))){%>
<script>alert("This user dont have PERMISSION to access this zone.");</script>
<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=admin_home.jsp"> 	
<%}

//GET PERMISSION

	String name = String.valueOf(session.getAttribute("name"));
	String surname = String.valueOf(session.getAttribute("surname"));
	String role_name = String.valueOf(session.getAttribute("curriculum_role"));
	
	String department_id = String.valueOf(session.getAttribute("department_id"));
			
	System.out.println("name : " + name);///////////////////////////////
	System.out.println("department_id : " + department_id);/////////////////////////
	
	List<String> system_name = new ArrayList<String>();
	
	Permission permission = new Permission(strUser,name);
	permission.setCurriculumCreate(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_create"))));
	permission.setCurriculumDelete(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_delete"))));
	permission.setCurriculumRead(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_read"))));
	permission.setCurriculumUpdate(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_update"))));
	
	String permiss = "";
	if(permission.getCurriculumCreate()) {
		permiss = permiss + "Add";
	}
	if(permission.getCurriculumUpdate()) {
		if("".equals(permiss)) {
			permiss = permiss + "Edit";
		} else {
			permiss = permiss + " Edit";
		}
	}
	if(permission.getCurriculumRead()) {
		if("".equals(permiss)) {
			permiss = permiss + "Read";
		} else {
			permiss = permiss + " Read";
		}
	}
	if(permission.getCurriculumDelete()) {
		if("".equals(permiss)) {
			permiss = permiss + "Delete";
		} else {
			permiss = permiss + " Delete";
		}
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////			
//check permission
	if(!permission.getCurriculumUpdate()){%>
		<script>alert("This user dont have PERMISSION to access this zone.");</script>
		<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=curriculum_home.jsp"> 	
	<%}

//set Database Connection
	String hostProps = "";
	String usernameProps  = "";
	String passwordProps  = "";
	String databaseProps = "";

	try {
		//get current path
		ServletContext servletContext = request.getSession().getServletContext();
		
		InputStream input = servletContext.getResourceAsStream("/properties/connectDB.properties");
		Properties props = new Properties();
		
		props.load(input);

		hostProps  = props.getProperty("host");
		usernameProps  = props.getProperty("username");
		passwordProps  = props.getProperty("password");
		databaseProps = props.getProperty("database");
	} catch (Exception e) { 
		out.println(e);  
	}
	
	System.out.println("hostProperties : "+hostProps);////////////////try/////////////////
	System.out.println("usernameProperties : "+usernameProps);////////////////try/////////////////
	System.out.println("passwordProperties : "+passwordProps);////////////////try/////////////////
	System.out.println("databaseProperties : "+databaseProps);////////////////try/////////////////
	
	// connect database
	Connection connect = null;		
	try {
		Class.forName("com.mysql.jdbc.Driver");
	
		connect =  DriverManager.getConnection("jdbc:mysql://" + hostProps  + "/" + databaseProps +
				"?user=" + usernameProps  + "&password=" + passwordProps + "&characterEncoding=tis620");//////"&characterEncoding=tis620" Encoding Thai);
	
		if(connect != null){
			System.out.println("Database Connect Sucesses.");
		} else {
			System.out.println("Database Connect Failed.");	
		}

	} catch (Exception e) {
		out.println(e.getMessage());
		e.printStackTrace();
	}
	
	// GET information from Curriculum
		
	String CurriculumId = request.getParameter("CurriculumId");
	String CurriculumNameENOLD = request.getParameter("nameCurriculumEN");
	int DepartmentIdOLD = Integer.parseInt((request.getParameter("departmentId")));
	String departmentOld = new String(request.getParameter("departmentName").getBytes("ISO8859_1"),"UTF-8");
	String YearOLD = request.getParameter("year");
	int Credit = Integer.parseInt(request.getParameter("credit"));
	
	String checker2 = request.getParameter("checker2"); 
	
	System.out.println("CurID:   "+CurriculumId);		
	System.out.println("CurriculumNameENOLD:   "+CurriculumNameENOLD);	
	System.out.println("DepartmentIdOLD:   "+DepartmentIdOLD);	
	System.out.println("departmentOld:   "+departmentOld);	
	System.out.println("YearOLD:   "+YearOLD);	
	System.out.println("Credit:   "+Credit);	
	
	int YearSemester = Integer.parseInt((request.getParameter("YearSemester")));
	int TermSemester = Integer.parseInt((request.getParameter("TermSemester")));
	int CreditSemester = Integer.parseInt((request.getParameter("CreditSemester")));

	System.out.println("YearSemester:   "+YearSemester);	
	System.out.println("TermSemester:   "+TermSemester);	
	System.out.println("CreditSemester:   "+CreditSemester);	
	
	int TotalCredit = 0;
	int CurrentCredit =0;
/////////////////////////////////////////////////////////////////////////////////////////////////

/*Find Semester_ID in DB*/
List<SemesterCourse> semester_courses = new ArrayList<SemesterCourse>();

try{
	ResultSet rs_SemesterCourse = connect.createStatement().executeQuery("SELECT `semester_program_id`, `curriculum_id`, `year`, `semester` "         
			+ " FROM semester_program"
			+ " WHERE curriculum_id ="+CurriculumId+" AND year="+YearSemester+" AND semester="+TermSemester	);
	
	while(rs_SemesterCourse.next()) {		
		SemesterCourse sem_course = new SemesterCourse();
		
		sem_course.setSemesterId(rs_SemesterCourse.getInt("semester_program_id"));
		semester_courses.add(sem_course);
		
		System.out.println("semester_courses.size:   "+semester_courses.size());	
	}
}catch (SQLException e) {
	e.printStackTrace();
}

int tempID = semester_courses.get(0).getSemesterId();
/////////////////////////////////////////////////////////////////////////////

/*Find Semester and Semester Program in DB for TotalCredit*/

List<SemesterCourse> semestercourse1 = new ArrayList<SemesterCourse>();

try{
	ResultSet rs_course1 = connect.createStatement().executeQuery("SELECT "
																+ "P.semester_program_id, P.curriculum_id, P.semester, P.year, P.credit, "
																+ "S.semester_program_id, S.course_id, S.course_name, S.credit, S.course_id_free_elective "
			+ " FROM semester_program P, course_semester S "
			+ " WHERE P.semester_program_id = S.semester_program_id AND S.semester_program_id="+tempID+" AND "
			+ " P.curriculum_id="+CurriculumId
			+ " ORDER BY S.course_id");
	
	while(rs_course1.next()) {		
		
		SemesterCourse SC1 = new SemesterCourse();
		
		SC1.setSemesterId(rs_course1.getInt("S.semester_program_id"));
		SC1.setCourseId(rs_course1.getString("S.course_id"));
		SC1.setCourseName(rs_course1.getString("S.course_name"));
		SC1.setCredit(rs_course1.getInt("S.credit"));
		SC1.setElective(rs_course1.getString("S.course_id_free_elective"));
		semestercourse1.add(SC1);
		System.out.println("semestercourse.size:   "+semestercourse1.size());	
			
	}
	
}catch (SQLException e) {
	e.printStackTrace();
}

for(int tempi= 0;tempi<semestercourse1.size();tempi++){
	// if 103 not cal cresit in term 1 year 1 
			
	//check year 1 term 1
	if(YearSemester == 1 && TermSemester == 1) {
		if("MUGE103".equals(semestercourse1.get(tempi).getCourseId())) {
			System.out.println("Total Current Credit:     "+ TotalCredit);
		}
		else {
			TotalCredit = TotalCredit +semestercourse1.get(tempi).getCredit();
			System.out.println("Total Current Credit:     "+ TotalCredit);
		}
	}
	//check year 1 term 2
	else if(YearSemester == 1 && TermSemester == 2) {
		if("LATH100".equals(semestercourse1.get(tempi).getCourseId())) {
			System.out.println("Total Current Credit:     "+ TotalCredit);
		}
		else if("MUGE101".equals(semestercourse1.get(tempi).getCourseId())) {
			System.out.println("Total Current Credit:     "+ TotalCredit);
		}
		else if("MUGE102".equals(semestercourse1.get(tempi).getCourseId())) {
			System.out.println("Total Current Credit:     "+ TotalCredit);
		}
		else {
			TotalCredit = TotalCredit +semestercourse1.get(tempi).getCredit();
			System.out.println("Total Current Credit:     "+ TotalCredit);
		}
	}
	else {
		TotalCredit = TotalCredit +semestercourse1.get(tempi).getCredit();
		System.out.println("Total Current Credit:     "+ TotalCredit);
	}	

}	

/////////////////////////////////////////////////////////////////////////////////////////////////

if(request.getParameter("checker2").equals("ADD_elec")){
	System.out.println("ADD_elec ADD_elec ADD_elec:     ");
	request.setCharacterEncoding("UTF-8");
	String checker = request.getParameter("search_box");
	
	if(checker == "") {
		%><script>alert("กรุณาเลือกรายวิชาก่อนค่ะ");</script><%
	}else{
	
		String courseId = "ELECTIV";		
		System.out.println("courseId :" + courseId);////////////////try////////////////
					
		String courseNameEN = "Free Elective";
		System.out.println("courseNameEN :" + courseNameEN);////////////////try////////////////	
		
		String tempcredit = "3";
		System.out.println("tempcredit :" + tempcredit);////////////////try////////////////					
		String[] split2 = tempcredit.split(" ");
		
		int credit = Integer.parseInt(split2[0]);
		System.out.println("credit :" + credit);////////////////try////////////////			
		
		//////////////////Temp
		//TEMP CREDIT
		int tempCredit = TotalCredit;// current total 135
		int tempMaxCredit = CreditSemester;//max 140
		int tempCreditSemester2 = credit; // 5
		int tempCheck = tempCredit+tempCreditSemester2;//135+5=140
		TotalCredit = tempCheck;
	
		// insert data to database			
		String sql_semester_course = "INSERT INTO  `course_semester`(`semester_program_id`, `course_id`, `course_name`, `credit`)"
							+ " VALUES ('"+ tempID +"', '"+ courseId +"', '"+ courseNameEN +"','"+ credit + "')";
		System.out.println(sql_semester_course);/////////////////////try///////////////////////////////
		if(tempMaxCredit < tempCheck){
			// If Max Credit < Current + Previous 
			TotalCredit = tempCredit;
			%><script>alert("หน่วยกิตรวมของแผนรายวิชาเกินหน่วยกิตของหลักสูตรค่ะ")</script><%
		}else{					
			try {		
					// insert data into semester course 
					connect.createStatement().executeUpdate("INSERT INTO  `course_semester`(`semester_program_id`, `course_id`, `course_name`, `credit`)"
							+ " VALUES ('"+ tempID +"', '"+ courseId +"', '"+ courseNameEN +"','"+ credit + "')");
					
					
					/* Log file */
					String log_user = strUser+" add course_schedule";
					Log.writeUserFile(log_user);
					Log.writeUserFile(sql_semester_course);
					
					%><script>alert("เพิ่มรายวิชาสำเร็จ")</script><%		
					
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

}
}
/////////////////////////////////////////////////////////////////////////////////////////////////

if(request.getParameter("checker2").equals("ADD")){

		request.setCharacterEncoding("UTF-8");
		String checker = request.getParameter("search_box");
		
		if(checker == "") {
			%><script>alert("กรุณาเลือกรายวิชาก่อนค่ะ");</script><%
		}else{
					
			String course_name = new String(request.getParameter("search_box").getBytes("ISO8859_1"),"UTF-8");
			System.out.println("course_name :" + course_name);////////////////try////////////////
			
			String[] split = course_name.split(" , ");
			System.out.println("split :" + split.length);////////////////try////////////////
			
			String courseId = split[0];			
			System.out.println("courseId :" + courseId);////////////////try////////////////
						
			String courseNameEN = split[1];
			System.out.println("courseNameEN :" + courseNameEN);////////////////try////////////////	
			
			String tempcredit = split[2];
			System.out.println("tempcredit :" + tempcredit);////////////////try////////////////					
			String[] split2 = tempcredit.split(" ");
			
			int credit = Integer.parseInt(split2[0]);
			System.out.println("credit :" + credit);////////////////try////////////////			
			
			//////////////////Temp
			//TEMP CREDIT
			
			int tempCredit = TotalCredit;// current total 135
			int tempMaxCredit = CreditSemester;//max 140
			int tempCreditSemester2 = credit; // 5
			int tempCheck = tempCredit;
					
			//check year 1 term 1
			if(YearSemester == 1 && TermSemester == 1) {
				if("MUGE103".equals(courseId)) {
					
				}
				else {
					tempCheck = tempCredit+tempCreditSemester2;//135+5=140
					TotalCredit = tempCheck;
				}
			}
			//check year 1 term 2
			else if(YearSemester == 1 && TermSemester == 2) {
				if("LATH100".equals(courseId)) {
					
				}
				else if("MUGE101".equals(courseId)) {
					
				}
				else if("MUGE102".equals(courseId)) {
	
				}
				else {
					tempCheck = tempCredit+tempCreditSemester2;//135+5=140
					TotalCredit = tempCheck;
				}
			}
			else {
				tempCheck = tempCredit+tempCreditSemester2;//135+5=140
				TotalCredit = tempCheck;
			}

////////////////////////////////////////////////////////////////////////////////
			int checker_dup = 0; //0 = not Duplicate, 1 = Duplicate		
			for(SemesterCourse semC : semestercourse1){
				if(semC.getCourseId().equals("ELECTIV")){								
					break;
				}
				
			
				if(semC.getCourseId().equals(courseId)){
					System.out.println("Duplicate ID:  "+courseId);
					System.out.println("////////////////////////////////////////////////////");
					checker_dup = 1;
				}
			}
			if(checker_dup == 0){
				// insert data to database			
				String sql_semester_course = "INSERT INTO  `course_semester`(`semester_program_id`, `course_id`, `course_name`, `credit`)"
									+ " VALUES ('"+ tempID +"', '"+ courseId +"', '"+ courseNameEN +"','"+ credit + "')";
				System.out.println(sql_semester_course);/////////////////////try///////////////////////////////
				if(tempMaxCredit < tempCheck){
					// If Max Credit < Current + Previous 
					TotalCredit = tempCredit;
					%><script>alert("หน่วยกิตรวมของแผนรายวิชาเกินหน่วยกิตของหลักสูตรค่ะ")</script><%
				}else{					
					try {		
							// insert data into semester course 
							connect.createStatement().executeUpdate("INSERT INTO  `course_semester`(`semester_program_id`, `course_id`, `course_name`, `credit`)"
									+ " VALUES ('"+ tempID +"', '"+ courseId +"', '"+ courseNameEN +"','"+ credit + "')");
							
							
							/* Log file */
							String log_user = strUser+" add course_schedule";
							Log.writeUserFile(log_user);
							Log.writeUserFile(sql_semester_course);
							
							%><script>alert("เพิ่มรายวิชาสำเร็จ")</script><%		
							
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				
			}else{//if(checker_dup == 0){
				%><script>alert("มีรายวิชานี้อยู่แล้วค่ะ")</script><%
				
			}
		}
}


/*Find Course Semester in DB*/
List<SemesterCourse> semestercourse = new ArrayList<SemesterCourse>();
List<Semester> semester = new ArrayList<Semester>();
System.out.println("tempID:   "+tempID);

try{
	ResultSet rs_course = connect.createStatement().executeQuery("SELECT "
																+ "P.semester_program_id, P.curriculum_id, P.semester, P.year, P.credit, "
																+ "S.semester_program_id, S.course_id, S.course_name, S.credit, S.course_id_free_elective "
			+ " FROM semester_program P, course_semester S "
			+ " WHERE P.semester_program_id = S.semester_program_id AND S.semester_program_id="+tempID+" AND "
			+ " P.curriculum_id="+CurriculumId
			+ " ORDER BY S.course_id");
	
	while(rs_course.next()) {		
		
		SemesterCourse SC = new SemesterCourse();
		
		SC.setSemesterId(rs_course.getInt("S.semester_program_id"));
		SC.setCourseId(rs_course.getString("S.course_id"));
		SC.setCourseName(rs_course.getString("S.course_name"));
		SC.setCredit(rs_course.getInt("S.credit"));
		SC.setElective(rs_course.getString("S.course_id_free_elective"));
		semestercourse.add(SC);
		System.out.println("semestercourse.size:   "+semestercourse.size());	
		
		Semester S = new Semester();
		
		S.setCurriculumId(rs_course.getInt("P.curriculum_id"));
		S.setSemester(rs_course.getInt("P.semester"));
		S.setYear(rs_course.getInt("P.year"));
		S.setCredit(rs_course.getInt("P.credit"));
		
		semester.add(S);
		System.out.println("semester.size:   "+semester.size());	
	}
	
}catch (SQLException e) {
	e.printStackTrace();
}

connect.close();
%>
	<div id="page-wrap">
		<div id="inside">
			<table border="0">
				<tr style="font-size:24px">
					<td width="600" height="100" style= "background-color: #273b80;border: 0px ;padding: 0px; 0px;" >
						<div id="header_banner-2"></div>
					</td>
					<td width="680" height="100" style= "background-color: #273b80;border: 0px;padding: 0px; 0px;" >
						<p align="right" ><label><font size="4" color="#FFFFFF">  username : <%=strUser %>&nbsp;&nbsp;</font></label></p>
						<a href="logout.jsp"><p align="right"><label style="cursor: pointer;"><font size="3" color="#ffffff">log out &nbsp;</font></label></p></a>
					</td>							
				</tr>
			</table>
    
				<div id="main-content-2">
					<label><font size="5">ชั้นปีที่  <%=YearSemester %> เทอมที่ <%=TermSemester %></font></label>
					
					<font size="4"> (ปัจจุบัน: <%=TotalCredit %> จาก <%=CreditSemester %> หน่วยกิต)</font></label>
				</div>
				
<!-- //////////////////////////////////////////////////////////////////////////////////// -->

				<div id="main-content-ac" align="center">

					<center>
			<form id="form1" name="form1" method="post" action="curriculum_add_course_schedule.jsp">
					<table>					
					<tr>	
						<td>
							<font size="4">กรุณาใส่รหัสวิชา </font>
							<label><font size="5" color="#FF0000">*</font></label>
						</td>						
						<td>
							<input type="text" autocomplete="off" placeholder="ex. egco111 หรือ electiv สำหรับวิชา  Free Elective" name="search_box" id="search_box" style="height: 25px; width: 400px; font-size:medium;" value="" list="namelist" onkeyup="search_name(this.value)" />
								<datalist id="namelist"></datalist>							
						</td>						
				  		<td>
				  				<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=CurriculumId%>" />
				  				<input type="hidden" id="nameCurriculumEN" name="nameCurriculumEN" value="<%=CurriculumNameENOLD%>" />
				  				<input type="hidden" id="departmentId" name="departmentId" value="<%=DepartmentIdOLD%>" />
				  				<input type="hidden" id="departmentName" name="departmentName" value="<%=departmentOld%>" />
				  				<input type="hidden" id="year" name="year" value="<%=YearOLD%>" />
				  				<input type="hidden" id="credit" name="credit" value="<%=Credit%>" />
				  								
				  				<input type="hidden" id="YearSemester" name="YearSemester" value="<%=YearSemester%>" />
				  				<input type="hidden" id="TermSemester" name="TermSemester" value="<%=TermSemester%>" />
				  				<input type="hidden" id="CreditSemester" name="CreditSemester" value="<%=CreditSemester%>" />
								<input type="hidden" id="checker" name="checker" value="none" />
												
								<input type="hidden" id="checker2" name="checker2" value="ADD" />	
												
				  				<input type="submit" value="add" name="add" id="add" class="buttonStyle"/>	
				  		</td>
				  							  		
				  	</tr>
				 </form>				  	
					  	
				  	</table>
						
					</center>
						
					
				</div>
				
<!-- //////////////////////////////////////////////////////////////////////////////////// -->
				
				<div id="main-content-ac" align="center">
					<div class="CSSTableGenerator">						
						<table  border="1">
							<tr style="font-size:22px">								
								<center>
									<td>&nbsp;&nbsp;&nbsp;</td>
									<td><center><strong>รหัสวิชา</strong></center></td>
									<td><center><strong>ชื่อวิชา(EN)</strong></center></td>
									<td><center><strong>หน่วยกิต</strong></center></td>
									<td><center>Delete</center></td>
							</tr>		
				<%// TEST EDIT				    
					int SemesterCourseCount = 1;
			    	int i=0;
			    	for(SemesterCourse  sem_cou: semestercourse ) {			    		
				%>
										<tr style="font-size:18px" id="Curriculum<%=SemesterCourseCount%>">
										<form id="form<%=SemesterCourseCount%>" name="form<%=SemesterCourseCount%>" method="post" action="curriculum_delete_course_schedule.jsp">
												
												<input type="hidden" id="SemesterKey" name="SemesterKey" value="<%=semester_courses.get(0).getSemesterId()%>" />	
										
												<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=CurriculumId%>" />
											  	<input type="hidden" id="nameCurriculumEN" name="nameCurriculumEN" value="<%=CurriculumNameENOLD%>" />
											  	<input type="hidden" id="departmentId" name="departmentId" value="<%=DepartmentIdOLD%>" />
											  	<input type="hidden" id="departmentName" name="departmentName" value="<%=departmentOld%>" />
											  	<input type="hidden" id="year" name="year" value="<%=YearOLD%>" />
											  	<input type="hidden" id="credit" name="credit" value="<%=Credit%>" />
											  								
											  	<input type="hidden" id="YearSemester" name="YearSemester" value="<%=YearSemester%>" />
											  	<input type="hidden" id="TermSemester" name="TermSemester" value="<%=TermSemester%>" />
											  	<input type="hidden" id="CreditSemester" name="CreditSemester" value="<%=CreditSemester%>" />
												<input type="hidden" id="checker" name="checker" value="none" />
																	
												<input type="hidden" id="checker2" name="checker2" value="none" />	
												
												
												<input type="hidden" id="CourseId" name="CourseId" value="<%=sem_cou.getCourseId()%>" />  
												<td id="SemesterCourseCount" name="SemesterCourseCount" align="center">
													<%=SemesterCourseCount%>
												</td>
												
												<td id="CourseId" name="CourseId" align="center">
													<%=sem_cou.getCourseId()%>
												</td>
												
												<input type="hidden" id="CourseName" name="CourseName" value="<%=sem_cou.getCourseName()%>" />  
												<td id="CourseNameEN<%=SemesterCourseCount%>" name="CourseNameEN<%=SemesterCourseCount%>" align="center">
													<%=sem_cou.getCourseName()%>
												</td>												
																							
												<input type="hidden" id="CreditCourseSemester" name="CreditCourseSemester" value="<%=sem_cou.getCredit()%>" /> 
												<td id="CreditNew<%=SemesterCourseCount%>" name="CreditNew<%=SemesterCourseCount%>" align="center">
													<center><%=sem_cou.getCredit()%></center>
												</td>
													
												
												
												<td><center><input type="image" src="image/delete_icon.png" height="30px" width="30px" /></center></td>
										
											</form>														
										</tr>
				
				<%
						i++;
						SemesterCourseCount++;

					}
			    
				%>					

								
						</table>
						<br><br>
					</div>
				<table>
				<br><br><font size="4" color="red">คำเตือน: ถ้ากดปุ่ม cancel ข้อมูลจะไม่ได้รับการบันทึก !</font><br><br>
				<% if(TotalCredit == CreditSemester){%>
					<form id="form5" name="form5" method="post" action="curriculum_add_schedule.jsp" onSubmit="alert('บันทึกข้อมูลวิชาสำเร็จ');">
						<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=CurriculumId%>" />
				  		<input type="hidden" id="nameCurriculumEN" name="nameCurriculumEN" value="<%=CurriculumNameENOLD%>" />
				  		<input type="hidden" id="departmentId" name="departmentId" value="<%=DepartmentIdOLD%>" />
				  		<input type="hidden" id="departmentName" name="departmentName" value="<%=departmentOld%>" />
				  		<input type="hidden" id="year" name="year" value="<%=YearOLD%>" />
				  		<input type="hidden" id="credit" name="credit" value="<%=Credit%>" />
				  								
				  		<input type="hidden" id="YearSemester" name="YearSemester" value="<%=YearSemester%>" />
				  		<input type="hidden" id="TermSemester" name="TermSemester" value="<%=TermSemester%>" />
				  		<input type="hidden" id="CreditSemester" name="CreditSemester" value="<%=CreditSemester%>" />
						<input type="hidden" id="checker" name="checker" value="none" />/>	
						
						<input type="hidden" id="delete" name="delete" value="none" />	
						<input type="hidden" id="sysID" name="sysID" value="none" />		
					<tr>
								<td height="50" width = "230">										
									<center><input type="submit" value="save" name="save" class="buttonStyle"/></center>	
								</td>
					</form>	
				<% }%>	
								
					<form id="form5" name="form5" method="post" action="curriculum_add_schedule.jsp">
					
						<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=CurriculumId%>" />
				  		<input type="hidden" id="nameCurriculumEN" name="nameCurriculumEN" value="<%=CurriculumNameENOLD%>" />
				  		<input type="hidden" id="departmentId" name="departmentId" value="<%=DepartmentIdOLD%>" />
				  		<input type="hidden" id="departmentName" name="departmentName" value="<%=departmentOld%>" />
				  		<input type="hidden" id="year" name="year" value="<%=YearOLD%>" />
				  		<input type="hidden" id="credit" name="credit" value="<%=Credit%>" />
				  								
				  		<input type="hidden" id="YearSemester" name="YearSemester" value="<%=YearSemester%>" />
				  		<input type="hidden" id="TermSemester" name="TermSemester" value="<%=TermSemester%>" />
				  		<input type="hidden" id="CreditSemester" name="CreditSemester" value="<%=CreditSemester%>" />
						<input type="hidden" id="checker" name="checker" value="none" />
								
						<input type="hidden" id="checker2" name="checker2" value="none" />	
						<input type="hidden" id="delete" name="delete" value="delete" />	
						<input type="hidden" id="sysID" name="sysID" value="<%=tempID %>" />								
								<td height="50" width = "230">										
									<center><input type="submit" value="cancel" name="cancel" class="buttonStyle"/></center>	
								</td>
					</tr>
					</form>	
				</table>
				<br><br>
				</div>
				<div style="clear: both;"></div>
					<div id="footer"></div>
		</div>	
					<div style="clear: both;"></div>	
    </div>
</body>
</html>